#region Summary

// 
// Owner : JackieHan 
// 
// Solution : Jackie.Utility
// 
// Project : Jackie.Utility.Test
// 
// File : TestLinQEqual.cs
// 
// CopyRight : Copyright © 2010-2011 Skomart Corporation, All Rights Reserved 
// 
// Summary : TestLinQEqual
// 
// History : 
//			2010-10-29 18:11:02	    Create 
// 

#endregion

#region Using

using System;
using System.Collections.Generic;
using NUnit.Framework;
using System.Linq;

#endregion

namespace Jackie.Utility.Test
{
    /// <summary> 
    /// TestLinQEqual
    /// </summary>
    [TestFixture]
    public class TestLinQEqual
    {
        [Test]
        public void Test()
        {
            IList<ViewInfo> viewInfos = ViewInfo.GetInitializeView();
            var query =viewInfos.Where(o => o.Tax == 1.45M);
            //from info in viewInfos.AsQueryable()Total=3.45 && 
            //where info.Total == 3.45
            //select info;
            IList<ViewInfo> decimalInfos = query.ToList();
            Assert.AreEqual(1, decimalInfos.Count);

            query = viewInfos.Where(o => o.Amount == 20.45F);
            IList<ViewInfo> floatInfos = query.ToList();
            Assert.AreEqual(1, floatInfos.Count);

            query = viewInfos.Where(o => o.Total == 3.45);
            IList<ViewInfo> doubleInfos = query.ToList();
            Assert.AreEqual(1, doubleInfos.Count);

        }
    }

    public class ViewInfo
    {
        public int Id { get; set; }
        public DateTime InvDate { get; set; }
        public string Name { get; set; }
        public float Amount { get; set; }
        public decimal Tax { get; set; }
        public double Total { get; set; }
        public string Note { get; set; }

        public static IList<ViewInfo> GetInitializeView()
        {
            IList<ViewInfo> viewInfos = new List<ViewInfo>();
            for (int i = 1; i <= 20; i++)
            {
                ViewInfo info = new ViewInfo
                {
                    Id = i,
                    Amount = (float)(i * 20.45),
                    InvDate = DateTime.Now.AddDays(i),
                    Name = string.Format("JackieHan{0}", i),
                    Note = string.Empty,
                    Tax = (decimal)(i * 1.45),
                    Total = (double)(3.45 * i)
                };
                viewInfos.Add(info);
            }
            return viewInfos;
        }
    }
}